package com.zzyl.controller;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelAddDto;
import com.zzyl.service.NursingLevelService;
import io.swagger.models.Response;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    public ResponseResult<?> listAll() {
        return ResponseResult.success(nursingLevelService.getAll());
    }

    @PostMapping("/insert")
    public ResponseResult<?> add(@RequestBody NursingLevelAddDto dto){
        nursingLevelService.add(dto);
        return ResponseResult.success();
    }

    @GetMapping("/listByPage")
    public ResponseResult<?> listByPage(@RequestParam("pageNum") Integer pageNum,
                                        @RequestParam("pageSize") Integer pageSize,
                                        @RequestParam(required = false) String name,
                                        @RequestParam(required = false) Integer status) {
        return ResponseResult.success(nursingLevelService.getByPage(pageNum, pageSize, name, status));
    }

    @GetMapping("/{id}")
    public ResponseResult<?> getById(@PathVariable("id") Integer id) {
        return ResponseResult.success(nursingLevelService.getById(id));
    }

    @PutMapping("/update")
    public ResponseResult<?> update(@RequestBody NursingLevelAddDto dto) {
        nursingLevelService.update(dto);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult<?> delete(@PathVariable("id") Integer id) {
        nursingLevelService.delete(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult<?> updateStatus(@PathVariable("id") Integer id, @PathVariable("status") Integer status) {
        nursingLevelService.updateStatus(id, status);
        return ResponseResult.success();
    }

}
